#include"myStruct.h"



int sizeSup(Supplier *);
void addAllSup(Supplier *,int );
void inputSup(int ,Supplier *);
void showSup(Supplier *,int );
void traversalSup(Supplier *);
int findByID(Supplier *,int ,int ,long long int );
void modifySup(Supplier *,int );
void removeSup(Supplier *,int );


int sizeGoods(Goods *);
void addAllGoods(Goods *,int );
void inputGoods(int ,Goods *);
void showGoods(Goods *,int);
void traversalGoods(Goods *);
int findByGoodsID(Goods *,int ,int ,long long int );
void modifyGoods(Goods *,int);
void removeGoods(Goods *,int);

int sizeProcure(Procure *);
void addAllProcure(Procure *,int );
void inputProcure(int ,Procure *);
void showProcure(Procure *,int);
void traversalProcure(Procure *);
int findByProcureID(Procure *,int ,int ,long long int );
void modifyProcure(Procure *,int);
void removeProcure(Procure *,int);

int sizeProcure2(Procure2 *);
void addAllProcure2(Procure2 *,int );
void inputProcure2(int ,Procure2 *);
void showProcure2(Procure2 *,int);
void traversalProcure2(Procure2 *);
int findByProcure2ID(Procure2 *,int ,int ,long long int );
void modifyProcure2(Procure2 *,int);
void removeProcure2(Procure2 *,int);

int sizeStaff(Staff *);
void addAllStaff(Staff *,int );
void inputStaff(int ,Staff *);
void showStaff(Staff *,int);
void traversalStaff(Staff *);
int findByStaffID(Staff *,int ,int ,long long int );
void modifyStaff(Staff *,int);
void removeStaff(Staff *,int);

int check(Staff *,int );

int check(Staff *a,int passWord)
{
	int i=0;
	while(i<sizeStaff(a))
	{
		if(a[i].pass==passWord)
		{
			return i;
		}
		i++;
	}
	return -1;
}

int sizeSup(Supplier *s)
{
	int i=0;
	while(s[i].ID!=0)
	{
		i++;
	}
	return i;
}

int sizeProcure(Procure *s)
{
	int i=0;
	while(s[i].ID!=0)
	{
		i++;
	}
	return i;
}

int sizeProcure2(Procure2 *s)
{
	int i=0;
	while(s[i].ID!=0)
	{
		i++;
	}
	return i;
}

int sizeStaff(Staff *s)
{
	int i=0;
	while(s[i].ID!=0)
	{
		i++;
	}
	return i;
}



//供应商编号，供应商名称，供应商简称，地址，公司电话，邮件，联系人，联系人电话，备注
void inputSup(int index,Supplier *a)
{
	printf("供应商编号：");
	scanf("%lld",&a[index].ID);
	printf("供应商名称：");
	fflush(stdin);
	gets (a[index].name);
	printf("供应商简称：");
	gets (a[index].abname);
	printf("地址：");
	gets (a[index].address);
	printf("公司电话：");
	scanf("%lld",&a[index].Phone);
	printf("邮件：");
	fflush(stdin);
	gets (a[index].email);
	printf("联系人：");
	gets (a[index].contacts);
	printf("联系人电话：");
	scanf("%lld",&a[index].conPhone);
	printf("备注：");
	fflush(stdin);
	gets (a[index].notes);
	
	printf("---------------------\n");
	
	return;
	
}
//员工编号，员工姓名，员工密码，员工级别，员工电话，员工工资，备注
void inputStaff(int index,Staff *a)
{
	printf("员工编号：");
	scanf("%lld",&a[index].ID);
	printf("员工名称：");
	fflush(stdin);
	gets (a[index].name);
	printf("员工密码：");
	scanf("%lld",&a[index].pass);
	printf("员工级别：");
	fflush(stdin);
	gets (a[index].title);
	printf("员工电话：");
	scanf("%lld",&a[index].Phone);
	printf("员工工资：");
	scanf("%f",&a[index].salary);
	printf("备注：");
	fflush(stdin);
	gets (a[index].notes);
	
	printf("---------------------\n");
	
	return;
	
}
//采购清单号，员工编号（外码），采购数量，采购总价，采购时间，备注
void inputProcure(int index,Procure *a)
{
	printf("采购单编号：");
	scanf("%lld",&a[index].ID);
	printf("员工编号：");
	scanf("%lld",&a[index].staffID);
	printf("采购数量：");
	scanf("%d",&a[index].number);
	printf("采购总价：");
	scanf("%f",&a[index].Total);
	printf("采购时间：");
	fflush(stdin);
	gets (a[index].time);
	printf("备注：");
	gets (a[index].notes);
	
	printf("---------------------\n");
	
	return;
	
}
//采购明细号，采购清单号（外码），商品编号（外码），采购数量，商品单价，商品总价，备注
void inputProcure2(int index,Procure2 *a)
{
	printf("采购单明细号：");
	scanf("%lld",&a[index].ID);
	printf("采购清单号：");
	scanf("%lld",&a[index].bID);
	printf("商品编码：");
	scanf("%lld",&a[index].sID);
	printf("采购数量：");
	scanf("%d",&a[index].number);
	printf("商品单价：");
	scanf("%f",&a[index].price);
	printf("商品总价：");
	scanf("%f",&a[index].sum);
	printf("备注：");
	fflush(stdin);
	gets (a[index].notes);
	
	printf("---------------------\n");
	
	return;
	
}

void addAllSup(Supplier *a,int n)
{
	int i=sizeSup(a);
	while(n>0)
	{
		inputSup(i,a);
		i++;
		n--;
	}
	
	return;
}

void addAllProcure(Procure *a,int n)
{
	int i=sizeProcure(a);
	while(n>0)
	{
		inputProcure(i,a);
		i++;
		n--;
	}
	
	return;
}

void addAllProcure2(Procure2 *a,int n)
{
	int i=sizeProcure2(a);
	while(n>0)
	{
		inputProcure2(i,a);
		i++;
		n--;
	}
	
	return;
}


void addAllStaff(Staff *a,int n)
{
	int i=sizeStaff(a);
	while(n>0)
	{
		inputStaff(i,a);
		i++;
		n--;
	}
	
	return;
}

void showProcure(Procure *a,int index)
{
	printf("采购单编号：");
	printf("%lld\n",a[index].ID);
	printf("员工编号：");
	printf("%lld\n",a[index].staffID);
	printf("采购数量：");
	printf("%d\n",a[index].number);
	printf("采购总价：");
	printf("%f\n",a[index].Total);
	printf("采购时间：");
	printf("%s\n",a[index].time);
	printf("备注：");
	printf("%s\n",a[index].notes);
	
	printf("---------------------\n");
	
	return;
}
//采购明细号，采购清单号（外码），商品编号（外码），采购数量，商品单价，商品总价，备注
void showProcure2(Procure2 *a,int index)
{
	printf("采购单明细号：");
	printf("%lld\n",a[index].ID);
	printf("采购单清单号：");
	printf("%lld\n",a[index].bID);
	printf("商品编码：");
	printf("%lld\n",a[index].sID);
	printf("采购数量：");
	printf("%d\n",a[index].number);
	printf("商品单价：");
	printf("%f\n",a[index].price);
	printf("商品总价：");
	printf("%f\n",a[index].sum);
	printf("备注：");
	printf("%s\n",a[index].notes);
	
	printf("---------------------\n");
	
	return;
}

void showSup(Supplier *a,int index)
{
	printf("供应商编号：");
	printf("%lld\n",a[index].ID);
	printf("供应商名称：");
	printf("%s\n",a[index].name);
	printf("供应商简称：");
	printf("%s\n",a[index].abname);
	printf("地址：");
	printf("%s\n",a[index].address);
	printf("公司电话：");
	printf("%lld\n",a[index].Phone);
	printf("邮件：");
	printf("%s\n",a[index].email);
	printf("联系人：");
	printf("%s\n",a[index].contacts);
	printf("联系人电话：");
	printf("%lld\n",a[index].conPhone);
	printf("备注：");
	printf("%s\n",a[index].notes);
	
	printf("---------------------\n");
	
	return;
}

void showStaff(Staff *a,int index)
{
	printf("员工编号：");
	printf("%lld\n",a[index].ID);
	printf("员工名称：");
	printf("%s\n",a[index].name);
	printf("员工密码：");
	printf("%lld\n",a[index].pass);
	printf("员工级别：");
	printf("%s\n",a[index].title);
	printf("员工电话：");
	printf("%lld\n",a[index].Phone);
	printf("员工工资：");
	printf("%f\n",a[index].salary);
	printf("备注：");
	printf("%s\n",a[index].notes);
	
	printf("---------------------\n");
	
	return;
}

void traversalSup(Supplier *a)
{
	int i=0;
	while(i<sizeSup(a))
	{
		showSup(a,i);
		i++;
	}
	
	return;
}

void traversalProcure2(Procure2 *a)
{
	int i=0;
	while(i<sizeProcure2(a))
	{
		showProcure2(a,i);
		i++;
	}
	
	return;
}

void traversalProcure(Procure *a)
{
	int i=0;
	while(i<sizeProcure(a))
	{
		showProcure(a,i);
		i++;
	}
	
	return;
}

void traversalStaff(Staff *a)
{
	int i=0;
	while(i<sizeStaff(a))
	{
		showStaff(a,i);
		i++;
	}
	
	return;
}



int findByID(Supplier *a,int begin,int end,long long int find)
{
	int flag=0;
	while(begin!=end)
	{
		if(a[begin].ID==find)
		{
			flag=1;
			break;
		}
		begin++;
	}
	
	if(flag==0)
	{
		return -1;
	}
	
	return begin;
}

int findByProcureID(Procure *a,int begin,int end,long long int find)
{
	int flag=0;
	while(begin!=end)
	{
		if(a[begin].ID==find)
		{
			flag=1;
			break;
		}
		begin++;
	}
	
	if(flag==0)
	{
		return -1;
	}
	
	return begin;
}

int findByProcure2ID(Procure2 *a,int begin,int end,long long int find)
{
	int flag=0;
	while(begin!=end)
	{
		if(a[begin].ID==find)
		{
			flag=1;
			break;
		}
		begin++;
	}
	
	if(flag==0)
	{
		return -1;
	}
	
	return begin;
}

int findByStaffID(Staff *a,int begin,int end,long long int find)
{
	int flag=0;
	while(begin!=end)
	{
		if(a[begin].ID==find)
		{
			flag=1;
			break;
		}
		begin++;
	}
	
	if(flag==0)
	{
		return -1;
	}
	
	return begin;
}

int findByGoodsID(Goods *a,int begin,int end,long long int find)
{
	int flag=0;
	while(begin!=end)
	{
		if(a[begin].ID==find)
		{
			flag=1;
			break;
		}
		begin++;
	}
	
	if(flag==0)
	{
		return -1;
	}
	
	return begin;
}



void modifySup(Supplier *s,int index)
{
	inputSup(index,s);
	return;
}

void modifyProcure(Procure *s,int index)
{
	inputProcure(index,s);
	return;
}

void modifyProcure2(Procure2 *s,int index)
{
	inputProcure2(index,s);
	return;
}

void modifyStaff(Staff *s,int index)
{
	inputStaff(index,s);
	return;
}

void modifyGoods(Goods *s,int index)
{
	inputGoods(index,s);
	return;
}



void removeSup(Supplier *s,int index)
{
    for (int i=index;i<sizeSup(s);i++) 
	{
        s[i]=s[i+1];
    }
    
    s[sizeSup(s)].ID=0;
    return;
}

void removeProcure(Procure *s,int index)
{
    for (int i=index;i<sizeProcure(s);i++) 
	{
        s[i]=s[i+1];
    }
    
    s[sizeProcure(s)].ID=0;
    return;
}

void removeProcure2(Procure2 *s,int index)
{
    for (int i=index;i<sizeProcure2(s);i++) 
	{
        s[i]=s[i+1];
    }
    
    s[sizeProcure2(s)].ID=0;
    return;
}

void removeStaff(Staff *s,int index)
{
    for (int i=index;i<sizeStaff(s);i++) 
	{
        s[i]=s[i+1];
    }
    
    s[sizeStaff(s)].ID=0;
    return;
}

void removeGoods(Goods *s,int index)
{
    for (int i=index;i<sizeGoods(s);i++) 
	{
        s[i]=s[i+1];
    }
    
    s[sizeGoods(s)].ID=0;
    return;
}


int sizeGoods(Goods *g)
{
	int i=0;
	while(g[i].ID!=0)
	{
		i++;
	}
	return i;
}

//商品编号，商品名称，商品单价，供应商编号，商品简介，备注
void inputGoods(int index,Goods *a)
{
	printf("商品编号：");
	scanf("%lld",&a[index].ID);
	printf("商品名称：");
	fflush(stdin);
	gets (a[index].name);
	printf("商品单价：");
	scanf("%f",&a[index].price);
	printf("供应商编号：");
	scanf("%lld",&a[index].supID);
	printf("商品简介：");
	fflush(stdin);
	gets (a[index].synopsis);
	printf("备注：");
	gets (a[index].notes);
	
	printf("---------------------\n");
	
	return;
	
}

void addAllGoods(Goods *a,int n)
{
	int i=sizeGoods(a);
	while(n>0)
	{
		inputGoods(i,a);
		i++;
		n--;
	}
	
	return;
}

void menu1_2_1(Goods *a)
{
	printf("输入添加个数：");
	int n;
	scanf("%d",&n);
	addAllGoods(a,n);
	printf("添加成功\n");
	system("pause");
	
	return;
}

void menu1_1_2(Goods *a)
{
	system("cls");
	printf("全部商品信息如下：\n\n");
	traversalGoods(a);
	system("pause");
	return;
}

void showGoods(Goods *a,int index)
{
	printf("商品编号：");
	printf("%lld\n",a[index].ID);
	printf("商品名称：");
	printf("%s\n",a[index].name);
	printf("商品单价：");
	printf("%f\n",a[index].price);
	printf("供应商编号：");
	printf("%lld\n",a[index].supID);
	printf("商品简介：");
	printf("%s\n",a[index].synopsis);
	printf("备注：");
	printf("%s\n",a[index].notes);
	printf("---------------------\n");
	return;
}

void traversalGoods(Goods *a)
{
	int i=0;
	while(i<sizeGoods(a))
	{
		showGoods(a,i);
		i++;
	}
	
	return;
}